random_forest_recp = recipe(diagnosis~.,data = train_data) |>
  # step_mutate(Cervical,Cervical = as.factor(Cervical))|>
  # step_mutate(pathology,pathology = as.factor(pathology))|>
  # step_dummy(Cervical,pathology) |>
  # step_select(diagnosis,sex,ALL,N,INR,Cr,bleeding,time,Cervical_X5,skip = FALSE) |>
  step_smotenc(diagnosis,over_ratio=0.5 ,neighbors=1,seed=123,skip = TRUE)


random_forest_spec = rand_forest() |>
  set_engine("ranger") |>
  set_mode("classification")

random_forest_flow = workflow() |>
  add_recipe(random_forest_recp) |>
  add_model(random_forest_spec)


random_forest_fit = fit(random_forest_flow,data = train_data)
random_forest_predict = augment(random_forest_fit,new_data=test_data)

random_forest_auc = roc_auc(data = random_forest_predict,truth = diagnosis,.pred_1,event_level="second")
random_forest_acc = accuracy(data = random_forest_predict,truth = diagnosis,.pred_class)
random_forest_sens = sensitivity(data=random_forest_predict,truth = diagnosis,.pred_class,event_level = "second")
random_forest_spec = specificity(data=random_forest_predict,truth = diagnosis,.pred_class,event_level = "second")
random_forest_ppv = ppv(data=random_forest_predict,truth = diagnosis,.pred_class,event_level = "second")
random_forest_conf_mat = conf_mat(data=random_forest_predict,truth = diagnosis,.pred_class)
random_forest_f_meas = f_meas(data=random_forest_predict,truth = diagnosis,.pred_class,event_level = 'second')

# random_forest_evaluation_table <- tibble(
#   metric = c("auc", "acc","sens","spec","ppv"),
#   value = c(auc$.estimate, acc$.estimate,sens$.estimate,spec$.estimate,ppv$.estimate)
# )
# 
# random_forest_evaluation_table

# conf_mat